<!-- 图文集 -->
<template>
    <div class="list" :style="boxStyle">
        <ul
            :class="{
                'sec-mode': !!mode
            }"
            class="list-container"
        >
            <template v-for="(item, index) in element.eles.content" :key="index">
                <li :style="itemStyle" class="list-item">
                    <el-image
                        :src="item.pic"
                        :style="itemImageStyle"
                        fit="fill"
                        class="list-img"
                    >
                        <template #placeholder>
                            <div class="picture-image-slot">
                                加载中...
                            </div>
                        </template>
                        <template #error>
                            <div class="picture-image-slot no-image">
                                {{ !item.pic ? '添加图片' : '图片错误' }}
                            </div>
                        </template>
                    </el-image>
                    <div class="title-container">
                        <p :style="itemTitleStyle" class="title-wrap">
                            {{ item.title }}
                        </p>
                        <p :style="itemSecTitleStyle" class="sec-title">
                            {{ item.secTitle }}
                        </p>
                    </div>
                </li>
            </template>
        </ul>
    </div>
</template>

<script>
import { defineComponent, toRefs, computed } from 'vue'
export default defineComponent({
    name: 'WidgetList',
    props: {
        element: {
            type: Object,
            default: () => ({})
        }
    },
    setup(props, { emit }) {
        const { element } = toRefs(props)

        const mode = computed(() => element.value.eles.customFeature.mode)

        const boxStyle = computed(() => {
            const style = element.value.eles.style || {}
            return {
                opacity: style.opacity,
                backgroundColor: style['background-color'],
                backgroundImage: style['background-image'],
                marginTop: style['margin-top']
            }
        })

        const containerStyle = computed(() => {
            const customFeature = element.value.eles.customFeature || {}
            return {
                paddingTop: `${customFeature['padding-top']}px`,
                paddingLeft: `${customFeature['padding-left']}px`
            }
        })

        const itemStyle = computed(() => {
            const customFeature = element.value.eles.customFeature || {}
            return {
                height: `${customFeature.lineHeight}px`,
                marginBottom: `${customFeature.margin}px`,
                backgroundColor: customFeature.lineBackgroundColor,
                backgroundImage: customFeature.lineBackgroundImage
            }
        })

        const itemImageStyle = computed(() => {
            const customFeature = element.value.eles.customFeature || {}
            return {
                width: `${customFeature.imgWidth}px`,
                height: `${customFeature.imgHeight}px`
            }
        })

        const itemTitleStyle = computed(() => {
            const style = element.value.eles.style || {}
            return {
                color: style.color,
                textAlign: style['text-align'],
                fontSize: style['font-size'],
                fontWeight: style['font-weight'],
                fontStyle: style['font-style'],
                textDecoration: style['text-decoration']
            }
        })

        const itemSecTitleStyle = computed(() => {
            const customFeature = element.value.eles.customFeature || {}
            return {
                textAlign: customFeature.secTextAlign,
                color: customFeature.secColor,
                fontSize: customFeature.secFontSize,
                fontWeight: customFeature.secFontWeight,
                fontStyle: customFeature.secFontStyle,
                textDecoration: customFeature.secTextDecoration
            }
        })

        return {
            element,
            mode,
            boxStyle,
            containerStyle,
            itemStyle,
            itemImageStyle,
            itemTitleStyle,
            itemSecTitleStyle
        }
    }
})
</script>

<style lang="less" scoped>
@import './widget-list.less';
</style>